import unittest

from django.test import TestCase
from django.test.client import Client
from django.core import urlresolvers

import client

class RemoteObjectTest(TestCase):
    
    def setUp(self):
        # Every test needs a client.
        self.client = Client()

    def test_details(self):
        # Check for errors
        from django.contrib.auth.models import User
        user = User(username='foo', is_staff=True, is_superuser=True)
        user.set_password('bar')
        user.save()
        post_data = client.prep_objects(User.objects.all(), username='foo', password='bar', action='change')
        response = self.client.post(urlresolvers.reverse('remote-objects'),
                                    post_data)
        self.failUnlessEqual(response.status_code, 200)
        
        post_data = client.prep_objects(User.objects.all())
        response = self.client.post(urlresolvers.reverse('remote-objects'),
                                    post_data)
        self.failUnlessEqual(response.status_code, 403)
        
        self.client.login(username='foo', password='bar')
        post_data = client.prep_objects(User.objects.all())
        response = self.client.post(urlresolvers.reverse('remote-objects'),
                                    post_data)
        self.failUnlessEqual(response.status_code, 200)

